package bit_0526_0312;

import java.util.Stack;

public class MinStack_0312 {
    Stack<Integer> stack1;
    Stack<Integer> stack2;
    public MinStack_0312() {
        stack1 = new Stack<>(); // 数据栈
        stack2 = new Stack<>(); // 辅助栈
    }

    public void push(int val) {
        stack1.push(val);
        if (stack2.empty()) {
            stack2.push(val);
        } else {
            int tmp = stack2.peek();
            if (tmp >= val) {
                stack2.push(val);
            }
        }

    }

    public void pop() {
        if (!stack1.empty()) {
            int tmp = stack1.pop();
            if (tmp == stack2.peek()) {
                stack2.pop();
            }
        }
    }

    public int top() {
        if (stack1.empty()) return -1;
        return stack1.peek();
    }

    public int getMin() {
        if (stack2.empty()) return -1;
        return stack2.pop();
    }
}
